package com.niit.onlinemusicserver.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.niit.onlinemusicserver.common.R;
import com.niit.onlinemusicserver.mapper.SongListMapper;
import com.niit.onlinemusicserver.model.domain.SongList;
import com.niit.onlinemusicserver.model.request.SongListRequest;
import com.niit.onlinemusicserver.service.SongListService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SongListServiceImpl extends ServiceImpl<SongListMapper, SongList> implements SongListService {

  @Autowired
  private SongListMapper songListMapper;

  @Override
  public R allSongList() {
    return R.success(null, songListMapper.selectList(null));
  }

  @Override
  public R addSongList(SongListRequest addSongListRequest) {
    SongList songList = new SongList();
    BeanUtils.copyProperties(addSongListRequest, songList);
    String pic = "/img/songListPic/123.jpg";
    songList.setPic(pic);
    if (songListMapper.insert(songList) > 0) {
      return R.success("添加成功");
    } else {
      return R.error("添加失败");
    }
  }

  @Override
  public R updateSongListMsg(SongListRequest updateSongListRequest) {
    SongList songList = new SongList();
    BeanUtils.copyProperties(updateSongListRequest, songList);
    if (songListMapper.updateById(songList) > 0) {
      return R.success("修改成功");
    } else {
      return R.error("修改失败");
    }
  }

  @Override
  public R deleteSongList(Integer id) {
    if (songListMapper.deleteById(id) > 0) {
      return R.success("删除成功");
    } else {
      return R.error("删除失败");
    }
  }
}
